import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:provider/provider.dart';
import 'package:tiktokadult/assets_tool/images.dart';

import '../../../alert_business/video/newer_vip_alert.dart';
import '../../../config/config.dart';
import '../../../routers/jump_router.dart';
import '../../../tools_base/global_store/store.dart';
import '../../main_page/provider/msg_provider.dart';
import '../../pre_sale/limit_time_event/limit_time_event_provider.dart';

class HomeLimitActivityWidget extends StatelessWidget {
  final EdgeInsetsGeometry? margin;
  HomeLimitActivityWidget({this.margin});

  @override
  Widget build(BuildContext context) {
    return Consumer<MineMsgProvider>(
      builder: (context, newser, child) => Consumer<LimitTimeEventProvider>(
        builder: (context, limitTime, child) {
          {
            //2.存在限时活动，显示限时活动
            // if (newser.timeEnd && limitTime.showLimitEvent()) return limitTime.limitBannerDetailView();
            //1.非会员 && 新人倒计时，显示新人倒计时
            if (!globalStore.isVIP() && newser.newerTime > 0 && Config.recommendVipIds?.isNotEmpty == true && newser.isShowNewerFloat) return _buildTimeCountView(newser);
            //3.会员 无任何展示
            return SizedBox();
          }
        },
      ),
    );
  }

  Widget _buildTimeCountView(MineMsgProvider newser) {
   return Container(
      margin: margin,
      child: InkWell(
        onTap: () async{
          await Get.dialog(NewerVipAlert());
          // await jumpToWalletPage();
          // await globalStore.updateUserInfo();
        },
        child: SizedBox(
          width: 60,
          height: 68,
          child: Stack(
            fit: StackFit.expand,
            children: [
              Positioned(
                top: 0,
                child: Image.asset(
                  "activity_time_icon.webp".homePath,
                  width: 60,
                  height: 60,
                ),
              ),
              Container(
                alignment: Alignment.bottomCenter,
                child: Container(
                  padding: EdgeInsets.symmetric(horizontal: 2, vertical: 2),
                  decoration: BoxDecoration(
                    color: Color(0xffE1351F),
                    borderRadius: BorderRadius.circular(3),
                  ),
                  child: Text(
                    '${newser.newerTimeHour}:${newser.newerTimeMin}:${newser.newerTimeSec}',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 10,
                      fontWeight: FontWeight.w700,
                    ),
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
